package com.hequ.merchant.banner.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hequ.merchant.banner.R;
import com.hequ.merchant.banner.entity.Module;
import com.hequ.merchant.banner.util.TimeUtil;

import java.util.List;

/**
 * Created by 柯尊诚 on 2015/10/23.
 * kzc
 */
public class ModuleAdapter extends BaseAdapter{

    private Context context;
    private List<Module> modules;

    public ModuleAdapter(Context context, List<Module> modules) {
        this.context = context;
        this.modules = modules;
    }

    @Override
    public int getCount() {
        return modules.size();
    }

    @Override
    public Module getItem(int position) {
        return modules.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.modules_adapter, null);
        }
        Module module = getItem(position);

        TextView tv_name = (TextView) convertView.findViewById(R.id.mtv_name);
        TextView tv_memo = (TextView) convertView.findViewById(R.id.mtv_memo);
        TextView tv_time = (TextView) convertView.findViewById(R.id.mtv_time);

        tv_name.setText(module.getName());
        tv_memo.setText(module.getMemo());
        tv_time.setText(TimeUtil.mm2time(module.getUpdateTime()));

        return convertView;
    }
}
